package org.chen.model.dao;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class BaseDAO {

	public static void close(ResultSet rs, PreparedStatement ps, Connection conn) {
		try {
			if (rs != null)
				rs.close();
			if (ps != null)
				ps.close();
			if (conn != null)
				conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConn() {
		Connection conn = null;
		try {
			Properties properties = new Properties();
			InputStream ins = Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties");
			properties.load(ins);
			String URL = properties.getProperty("URL");
			String DRIVER = properties.getProperty("DRIVER");
			String USER = properties.getProperty("USER");
			String PWD = properties.getProperty("PWD");
			Class.forName(DRIVER);
			conn = DriverManager.getConnection(URL, USER, PWD);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void main(String[] args) {
		getConn();
	}

}
